<?php

namespace App\Remote\EKuaiBao;

use App\Enums\BaseErrorCode;
use App\Exceptions\Custom\ResponseHttpException;
use App\Remote\Remote;
use Closure;
use GuzzleHttp\Psr7\Response;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Request as RequestAlias;
use Symfony\Component\HttpFoundation\Response as ResponseAlias;

class BaseRemote extends Remote
{
    public static int $requestTimeOut = 60;

    static function getBaseUri(): string
    {
        // TODO: Implement getBaseUri() method.
        return "https://feishu.ekuaibao.com";
    }

    public static function buildBasicHeaders(): array
    {
        return [
            "Content-Type" => "application/json"
        ]; // TODO: Change the autogenerated stub
    }

    public static function registerResponseHandle(): Closure
    {
        return function () {
            list($responseHttpCode, $responseContent) = func_get_args();
            if ($responseHttpCode != ResponseAlias::HTTP_OK) {
                throw new \Exception($responseContent);
            }

            $responseContentArr = json_decode($responseContent, true);
            if (!empty($responseContentArr["value"]["errorCode"])) {
                throw new \Exception("{$responseContentArr["value"]["errorMessage"]}");
            }

            return $responseContentArr;
        };
    }
}
